from django.db import models


class DailyTheme(models.Model):
    """每日主题模型"""
    
    title = models.CharField(
        max_length=200,
        db_comment='主题标题'
    )
    description = models.TextField(
        blank=True, 
        null=True,
        db_comment='主题描述'
    )
    theme_date = models.DateField(
        unique=True,
        db_comment='主题日期'
    )
    created_at = models.DateTimeField(
        auto_now_add=True,
        db_comment='创建时间'
    )
    
    class Meta:
        db_table = 'creation_daily_themes'
        db_table_comment = '每日创作主题表'
        verbose_name = '每日主题'
        verbose_name_plural = '每日主题管理'
        ordering = ['-theme_date']
        indexes = [
            models.Index(fields=['theme_date']),
        ]
    
    def __str__(self):
        return f"{self.theme_date} - {self.title}"
    
    @classmethod
    def get_today_theme(cls):
        """获取今日主题"""
        from datetime import date
        return cls.objects.filter(theme_date=date.today()).first()
